// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using SnapObjects.Commons;

namespace SnapObjects.Data
{
    internal class ModelUpdateException : Exception
    {
        public ModelUpdateException([NotNull] string message, [CanBeNull] Exception innerException)
            : base(message, innerException)
        {
        }

        public ModelUpdateException([NotNull] string message, [CanBeNull] Exception innerException, [NotNull] ModelUpdateInfo modelUpdateInfo)
            : base(message, innerException)
        {
            IList<ModelUpdateInfo> modelsToUpdate = new List<ModelUpdateInfo>
            {
                modelUpdateInfo
            };
            this.ModelsToUpdate = (IReadOnlyList<ModelUpdateInfo>)modelsToUpdate;
        }

        public ModelUpdateException([NotNull] string message, [CanBeNull] Exception innerException, [NotNull] IReadOnlyList<ModelUpdateInfo> modelUpdateInfos)
            : base(message, innerException)
        {
            Check.NotEmpty(modelUpdateInfos, nameof(modelUpdateInfos));
            this.ModelsToUpdate = modelUpdateInfos;
        }

        public ModelUpdateException([NotNull] string message, [CanBeNull] Exception innerException, [NotNull] object modelUpdateInfos)
            : base(message, innerException)
        {
            this.UpdateFailedModels = new List<object>()
            {
                modelUpdateInfos
            };
        }

        public IReadOnlyList<ModelUpdateInfo> ModelsToUpdate { get; }

        public IReadOnlyList<object> UpdateFailedModels { get; }
    }
}
